package com.unity.bh3.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.unity.bh3.entity.UserItem;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户背包Mapper接口
 */
@Mapper
public interface UserItemMapper extends BaseMapper<UserItem> {
    
    /**
     * 根据用户ID查询背包物品列表
     * @param userId 用户ID
     * @return 背包物品列表
     */
    @Select("SELECT * FROM user_item WHERE user_id = #{userId} AND quantity > 0 ORDER BY create_time DESC")
    List<UserItem> selectUserItemsWithDetails(@Param("userId") Long userId);
    
    /**
     * 根据用户ID和物品ID查询背包物品
     * @param userId 用户ID
     * @param itemId 物品ID
     * @return 背包物品
     */
    @Select("SELECT * FROM user_item WHERE user_id = #{userId} AND item_id = #{itemId}")
    UserItem selectByUserIdAndItemId(@Param("userId") Long userId, @Param("itemId") Long itemId);
    
    /**
     * 根据用户ID和物品类型查询物品ID列表
     * @param userId 用户ID
     * @param itemType 物品类型
     * @return 物品ID列表
     */
    @Select("SELECT item_id FROM user_item WHERE user_id = #{userId} AND item_type = #{itemType} AND quantity > 0")
    List<Long> selectItemIdsByUserIdAndType(@Param("userId") Long userId, @Param("itemType") Integer itemType);
}